package com.huaxin.hxmoduleworkorder.common.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.huaxin.hxmoduleworkorder.common.enums.base.BaseCodeEnum;

/**
 * 任务/工单优先级枚举
 */
public enum MaintenanceOrderPriority implements BaseCodeEnum {

    LOW("low", "低", 1),
    MEDIUM("medium", "中", 2),
    HIGH("high", "高", 3),
    URGENT("urgent", "紧急", 4);

    @EnumValue
    private final String code;
    private final String displayName;
    private final int level;

    MaintenanceOrderPriority(String code, String displayName, int level) {
        this.code = code;
        this.displayName = displayName;
        this.level = level;
    }

    @JsonValue
    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDisplayName() {
        return displayName;
    }

    public int getLevel() {
        return level;
    }

    public static MaintenanceOrderPriority of(String code) {
        if (code == null) return null;
        for (MaintenanceOrderPriority priority : values()) {
            if (priority.getCode().equalsIgnoreCase(code)) {
                return priority;
            }
        }
        return null;
    }

    public static boolean isValid(String code) {
        return of(code) != null;
    }

    /**
     * 是否高于另一个优先级
     */
    public boolean isHigherThan(MaintenanceOrderPriority other) {
        return this.level > other.level;
    }
}
